#! /usr/bin/env python
#coding=utf-8

import os, sys

def populate_export_file(num):
    if not os.path.exists("/sys/class/gpio/gpio" + str(num)) :
        try:
            f = file('/sys/class/gpio/export', 'w')
            f.write(str(num))
            f.close()
        except IOError, e:
            print e
            return
    f = file('/sys/class/gpio/gpio' + str(num) + '/direction', 'w')
    f.write('out')
    f = file('/sys/class/gpio/gpio' + str(num) + '/value', 'w')
    f.write('1')
    f.close()

if __name__ == '__main__':
    populate_export_file(17)
